<!--
	* @author gaohailan
  * @desc 创新成果 创新成果分类
-->
<template>
  <div class="innovationAchievementClassify">
    <el-collapse-transition>
      <div class="common-search merge">
        <span class="svg-container">
          <svg-icon icon-class="search"/>
        </span>
        <el-input
          v-model="listQuery.name"
          class="search-input"
          clearable
          placeholder="输入分类名称搜索"
          @keyup.enter.native="handleFilter"
        />
        <div class="common-search-btn">
          <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
          <el-button class="filter-item" type="primary" @click="resettingBtn">重置</el-button>
        </div>
      </div>
    </el-collapse-transition>
    <div class="btn-container">
      <div class="btn-container-title">
        <span>职工创新成果分类</span>
      </div>
      <div class="btn-container-btns">
        <el-button class="filter-item" style="margin-left: 10px;" @click="handle()">新建分类</el-button>
        <el-button class="filter-item" style="margin-left: 10px;" @click="handleDeletes">批量删除</el-button>
      </div>
    </div>
    <div class="table">
      <el-table
        ref="rolemantable"
        v-loading="listLoading"
        :data="list"
        :header-cell-style="rowClass"
        class="tableScope"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"/>
        <el-table-column label="分类名称" prop="name" show-overflow-tooltip/>
        <el-table-column label="创建时间" prop="crtTime" show-overflow-tooltip/>
        <el-table-column label="状态" prop="status" show-overflow-tooltip width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.status == 0 ? '启用' : '禁用' }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" class-name="small-padding fixed-width" fixed="right" label="操作" width="200">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="handle(scope.row)">编辑</el-button>
            <el-button size="mini" type="text" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="btn-pagion fix">
      <pagination
        v-show="total>0"
        :limit.sync="listQuery.limit"
        :page.sync="listQuery.page"
        :total="total"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import {del, queryPage} from '../api.js'
import waves from '@/directive/waves' // Waves directive
import Pagination from '@/components/Pagination'
export default {
  name: 'InnovationAchievementClassify',
  components: {Pagination},
  directives: {waves},
  props: [],
  data() {
    return {
      listQuery: {
        page: 1,
        pageSize: 10,
        name: ''
      },
      search: {
        name: ''
      },
      list: [],
      total: 0,
      multipleSelection: [],
      listLoading: false
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList(obj) {
      this.listLoading = true
      var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.pageSize,
        name: this.listQuery.name
      }
      return new Promise((resolve, reject) => {
        queryPage(query).then(response => {
          this.list = response.data.data.rows
          this.total = response.data.data.total
          this.listLoading = false
        }).catch(error => {
          reject(error)
          this.listLoading = false
        })
      })
    },
    rowClass({row, rowIndex}) {
      return {
        padding: '5px 0',
        height: '20px',
        background: 'rgba(247,247,248,1)'
      }
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    resettingBtn() {
      this.listQuery.page = 1
      this.listQuery.name = ''
      this.search.name = ''
      this.getList()
    },

    handle(row) {
      if (!row) {
        this.$router.push({
          path: this.$filterPath('manage'),
          query: { type: 'c'}
        })
      } else {
        this.$router.push({
          path: this.$filterPath('manage'),
          query: {i: row.id, type: 'u'}
        })
      }
    },

    /*
    * 删除
    * */
    handleDeletes() {
      const arr = []
      if (this.multipleSelection.length > 0) {
        this.$confirm('将永久删除该分类, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.multipleSelection.forEach(item => {
            arr.push(item.id)
          })
          const ids = arr.join(',')
          this.deleteNotice(ids)
        })
          .catch(() => {
          })
      } else {
        this.$message({
          message: '请选择需要删除的数据！',
          type: 'warning'
        })
      }
    },
    handleDelete(row) {
      this.$confirm('将永久删除该分类, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteNotice(row.id)
      })
        .catch(() => {
        })
    },
    deleteNotice(ids) {
      del({ids: ids}).then(() => {
        this.$notify({
          title: '成功',
          message: '删除成功',
          type: 'success',
          duration: 2000
        })
        this.getList()
      })
    },
    handleSelectionChange(arr) {
      this.multipleSelection = arr
    }
  }
}
</script>

<style lang="scss">
$dark_gray: #bfced6;
$mainColor: #18A5FD;
.innovationAchievementClassify {
  padding: 20px;

  .common-search {
    background-color: #fff;
    padding: 0 20px;

    .svg-container {
      padding: 0;
      color: $dark_gray;
      vertical-align: middle;
      display: inline-block;

      &_login {
        font-size: 20px;
      }
    }

    .search-input {
      width: 60%;
      position: relative;

      &:after {
        content: "";
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }

      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;

        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }

    .common-search-btn {
      display: inline-block;
      float: right;

      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }

      .common-search-more {
        font-size: 14px;
        font-weight: 500;
        color: $mainColor;
        cursor: pointer;
        margin-left: 10px;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }

    &.separate {
      .common-search-inner {
        padding-top: 10px;

        .search-inner-item {
          .item-label {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #A6A6A6;
            font-weight: 400;
          }

          .el-input {
            position: relative;

            .el-input__inner {
              border: none;
              padding: 0;
            }

            &:after {
              content: "";
              height: 1px;
              background-color: #E2E3E8;
              position: absolute;
              left: 0;
              right: 0;
              bottom: 0;
            }
          }
        }
      }

      .common-search-btn {
        text-align: center;
        display: block;
        float: none;
        height: 56px;
        line-height: 56px;
      }
    }
  }

  .btn-container {
    display: flex;
    height: 36px;
    line-height: 36px;
    margin-top: 15px;

    .btn-container-title {
      flex: 1;
      height: 36px;
      line-height: 36px;
      font-size: 16px;
      color: rgba(51, 51, 51, 1);
    }
  }

  .dataForm::-webkit-scrollbar {
    display: none;
  }
}
</style>
